/*
 * @lc app=leetcode.cn id=202 lang=cpp
 *
 * [202] 快乐数
 */

// @lc code=start
class Solution
 {
public:
    long long  help(long long num)
    {
        long long ret=0;
        while(num)
        {
            int tem=num%10;
            ret+=tem*tem;
            num/=10;
        }
        return ret;
    }

    bool isHappy(int n) 
    {
        long long  slow=n;
        long long fast=help(n);
        while(slow!=fast)
        {
            slow=help(slow);
            fast=help(help(fast));
        }
        return slow==1;
    }
};
// @lc code=end

